#include "spi_driver.h"

static struct spi_client spi_client_array[MAX_BUS_NUM] = {
    #ifdef ESP32
    {
        .bus_num = SPI3,
        .is_init = 0,
        .chan = 3,
        .buscfg = {
            .miso_io_num = 19,
            .mosi_io_num = 23,
            .sclk_io_num = 18,
            .quadwp_io_num = -1,
            .quadhd_io_num = -1,
            .max_transfer_sz = 16 * 320 * 2 + 8
        },
    },
    {.bus_num = SPI_NONE},
    #endif
};

#ifdef ESP32
int SpiMasterInit()
{
    esp_err_t ret = 0;
    struct spi_client *client;
    for(int i = 0; i < MAX_BUS_NUM; i++)
    {
        if(spi_client_array[i].bus_num == SPI_NONE)
            break;
        client = &spi_client_array[i];
        ret = spi_bus_initialize(client[i].bus_num,&client[i].buscfg,client[i].chan);
        if(ret != ESP_OK)
            return ret;
        client[i].is_init = 1;
    }

    return ESP_OK;
}
#else
int SpiInit(struct spi_client*client,void *data)
{

    
}
#endif
